package com.campus.client.view;

import javafx.scene.control.Button;

public class SidebarButton extends Button {

    private boolean selected = false;

    public SidebarButton(String text) {
        super(text);
        setStyle(defaultStyle());

        // 悬停效果（仅在未选中时有效）
        this.setOnMouseEntered(e -> {
            if (!selected) {
                setStyle(hoverStyle());
            }
        });

        this.setOnMouseExited(e -> {
            if (!selected) {
                setStyle(defaultStyle());
            }
        });
    }

    /** 设置选中状态 */
    public void setSelected(boolean value) {
        this.selected = value;
        if (selected) {
            setStyle(selectedStyle());
        } else {
            setStyle(defaultStyle());
        }
    }

    public boolean isSelected() {
        return selected;
    }

    /** 默认样式 */
    private String defaultStyle() {
        return "-fx-background-color: transparent;"
                + "-fx-text-fill: white;"
                + "-fx-font-size: 16px;"
                + "-fx-font-weight: bold;"
                + "-fx-alignment: center-left;"
                + "-fx-padding: 5 10 5 15;";  // 给文字一点左边距
    }

    /** 悬停样式 */
    private String hoverStyle() {
        return "-fx-background-color: rgba(0, 0, 0, 0.3);" // 背景半透明黑
                + "-fx-text-fill: white;"
                + "-fx-font-size: 16px;"
                + "-fx-font-weight: bold;"
                + "-fx-alignment: center-left;"
                + "-fx-padding: 5 10 5 15;";
    }

    /** 选中样式 */
    private String selectedStyle() {
        return "-fx-background-color: rgba(0, 0, 0, 0.3);"   // 背景更暗
                + "-fx-text-fill: #FFD700;"                  // 金黄色字体
                + "-fx-font-size: 16px;"
                + "-fx-font-weight: bold;"
                + "-fx-alignment: center-left;"
                + "-fx-padding: 5 10 5 15;"
                + "-fx-border-color: transparent transparent transparent #FFD700;" // 左边黄色竖线
                + "-fx-border-width: 0 0 0 4;"
                + "-fx-border-insets: 0;"
                + "-fx-border-style: solid;";
    }
}
